/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import modelo.Questionario;
import modelo.QuestionarioHasQuestao;

/**
 *
 * @author Caps
 */
@Stateless
public class QuestionarioFacade extends AbstractFacade<Questionario> {

    @PersistenceContext(unitName = "SagrauPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public QuestionarioFacade() {
        super(Questionario.class);
    }

    public List<QuestionarioHasQuestao> findQuestao(Integer idQuestionario) {
        TypedQuery<Questionario> q = getEntityManager().createQuery("select q from Questionario q where q.idquestionario =:arg", Questionario.class).setParameter("arg", idQuestionario);

        q.setMaxResults(1);

        List<Questionario> lista = q.getResultList();
        if (lista == null || lista.isEmpty()) {
            return null;
        }else{
            return lista.get(0).getQuestionarioHasQuestaoList();
        }
    }
}
